<template>
  <view class="product-grid">
   <view 
     v-for="item in productList" 
     :key="item.id"
     class="product-item"
     @click="goToProductDetail(item.id)"
   >
      <view class="img-box">
        <image
          :src="item.image"
          mode="aspectFit"
          class="product-img"
        />
      </view>
      <view class="info">
        <text class="name">{{item.name}}</text>
        <text class="price">¥{{item.price}}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      productList: [
        {
          id: 1,
          name: "《牡丹》",
          price: 999,
          image: require('@/static/products/product1.jpg')
        },
        {
          id: 2,
          name: "《竹枝栖雀图》",
          price: 888,
          image: require('@/static/products/product2.jpg')
        },
        {
          id: 3,
          name: "《蝶舞绮扇》",
          price: 666,
          image: require('@/static/products/product3.jpg')
        },
        {
          id: 4,
          name: "《鹊立玉兰枝》",
          price: 1299,
          image: require('@/static/products/product4.jpg')
        },
        {
          id: 5,
          name: "《繁花间鹊影》",
          price: 899,
          image: require('@/static/products/product5.jpg')
        },
        {
          id: 6,
          name: "《荷间鹊望》",
          price: 998,
          image: require('@/static/products/product6.jpg')
        },
        // 其他商品...
      ]
    }
  },
  methods: {
    goToProductDetail(productId) {
      // 使用小程序的跳转方式
      wx.navigateTo({
        url: `/pages/product/detail?id=${productId}` // 跳转到商品详情页并传递商品ID
      });
    }
  }
}
</script>

<style scoped>
/* 样式保持不变 */
.product-grid {
  display: flex;
  flex-wrap: wrap;
  padding: 10px;
  box-sizing: border-box;
}

.product-item {
  width: 48%;
  margin: 1%;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.img-box {
  width: 100%;
  height: 180px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f7f7f7;
}

.product-img {
  max-width: 100%;
  max-height: 100%;
}

.info {
  padding: 10px;
  text-align: center;
}

.name {
  font-size: 14px;
  color: #333;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.price {
  font-size: 16px;
  color: #e4393c;
  font-weight: bold;
  margin-top: 5px;
  display: block;
}
</style>